/**
 * Created by Amaris on 2016/10/9.
 */

var Waterline = require('waterline');
var uuid = require('node-uuid');
var moment = require('moment');

/**
 * 用户参与表
 * @type {void|*}
 */
module.exports = Waterline.Collection.extend({
    identity: 'userjoin',
    tableName: 'tb_userjoin',
    connection: "mysql",
    attributes: {

        rowId: {
            type: 'string',
            primaryKey: true,
            unique: true,
            required: true,
            uuidv4: true,
            columnName: 'rowid',
            defaultsTo: function() {
                return uuid.v4();
            }
        },
        actionId: {
            type: 'string',
            required: true,
            columnName: 'actionid'
        },
        userId: {
            type: 'string',
            required: true,
            columnName: 'userid',
            model: 'user'
        },
        actionType: {
            type: 'string',
            required: true,
            columnName: 'actiontype'
        },
        userType: {
            type: 'string',
            required: true,
            columnName: 'usertype'
        },
        joinType: {
            type: 'string',
            columnName: 'jointype'
        },
        createUid: {
            type: 'string',
            required: true,
            columnName: 'createuid',
            model: 'user'
        },
        updateTime: {
            type: 'string',
            columnName: 'updatetime'
        },
        /**
         * 2017年04月14日新增  2017年06月25日废弃
         */
        // teamId:{
        //     type: 'string',
        //     columnName: 'teamid'
        // },
        toJSON: function() {
            var obj = this.toObject();

            obj.createdAt=moment(obj.createdAt).format('YYYY/MM/DD hh:mm');
            obj.updatedAt=moment(obj.updatedAt).format('YYYY/MM/DD hh:mm');

            return obj;
        }

    }
});
